package com.example.myworkers.service.imp;/*
 *编写者：陆铭
 */

import com.example.myworkers.dao.IRole;
import com.example.myworkers.model.Role;
import com.example.myworkers.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class IRoleServiceImpl implements IRoleService {
    @Autowired
    private IRole roleMapper;

    //增加新角色
    @Override
    public int insertRole(Role role){
        int roleValue=0;
        Role role1=new Role();
        role1.setName(role.getName());
        List<Role> getR=roleMapper.getAllRole(role1);
        if(getR.size()>=1){
            roleValue=-1;
        }else {
            roleValue=roleMapper.insertRole(role);
        }
        return roleValue;
    }
    //查找全部角色
    @Override
    public  List<Role> getAllRole(Role role){
        return roleMapper.getAllRole(role);
    }

    //修改方法
    @Override
    public int updateRole(Role role){
        int roleValue=0;
        Role role1=new Role();
        role1.setName(role.getName());
        if(role.getId()!=0){
            if(role.getId()!=0){
                if(role1.getName()!=role.getName()){
                    roleValue=-1;
                }
            }
            roleValue=roleMapper.updateRole(role);
        }
        return roleValue;
    }

    //删除方法
    @Override
    public int deleteRole(Role role){
        int roleValue=0;
        if(role.getId()!=0){
            roleValue=roleMapper.deleteRole(role);
        }
        return roleValue;
    }

    @Override
    public Role getRole(Role role){
        Role role1=new Role();
        if(role.getId()!=0){
            role1=roleMapper.getRole(role);
        }
        return role1;
    }
}
